import base64
import hashlib
import json
import time

import requests


def token1():
    t = int(time.time())  # 获取10位整数的时间戳
    s1 = f'/api/movie,{t}'
    o = hashlib.sha1(s1.encode('utf-8')).hexdigest()  # 进行SHA1加密
    str_str = str(f"{o},{t}")
    bytesStr = str_str.encode(encoding='utf-8')
    b64str = base64.b64encode(bytesStr)  # 最后的base64加密
    b64str_all = b64str.decode('utf-8')  # 将字节转换为str
    print(b64str_all)
    return b64str_all


if __name__ == '__main__':
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                             'Chrome/87.0.4280.141 Safari/537.36'}
    the_url = "https://spa6.scrape.center/api/movie/?limit=10&offset=" + str(0 * 10) + "&token=" + token1()
    index = requests.get(the_url, headers=headers, verify=False)
    dict_data = json.loads(index.text)  # 将响应的内容转化为json
    print(dict_data)
